package com.travel.photos.ui.recommend;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;

import com.travel.R;
import com.travel.photos.base.BaseActivity;
import com.travel.photos.base.BaseFragment;

import butterknife.Bind;
import tools.EndLessOnScrollListener;

/**
 * Created by meidou on 2016/10/18.
 * 发现的fragment
 */
public class RecommendFragment extends BaseActivity implements RecommendContract.View{
    @Bind(R.id.photo_recommend_recycle)
    RecyclerView mPhototRecycle;
    @Bind(R.id.photo_toolbar)
    Toolbar photo_toolbar;
    private LinearLayoutManager mManager;
    private RecommendContract.Presenter mPresenter;
    @Override
    public void getDetail(RecommentAdapter adapter) {
        mPhototRecycle.setAdapter(adapter);
    }
    @Override
    public void initData() {
        mPresenter = new RecommendPresenter(this);
        mPresenter.getDetail(this);
    }

    @Override
    public void initViews() {
        setSupportActionBar(photo_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        photo_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mManager = new LinearLayoutManager(this);
        mManager.setOrientation(LinearLayoutManager.VERTICAL);
        mPhototRecycle.setLayoutManager(mManager);
        mPhototRecycle.setItemAnimator(new DefaultItemAnimator());
        //上拉加载
        mPhototRecycle.addOnScrollListener(new EndLessOnScrollListener(mManager) {
            @Override
            public void onLoadMore(int currentPage) {
              //  mPresenter.UpRefresh(getContext());
            }
        });
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_photot_recommend;
    }
}
